const state = {
  attrList: JSON.parse(sessionStorage.getItem('attrList')) || [],
  listTotal: sessionStorage.getItem('listTotal') || 0,
  isShowBack: sessionStorage.getItem('isShowBack') || false,
  queryParams: JSON.parse(sessionStorage.getItem('queryParams')) || { size: 10, current: 1 },
  historyArr: JSON.parse(sessionStorage.getItem('historyArr')) || [],
  assetsObj: JSON.parse(sessionStorage.getItem('assetsObj')) || {},
  searchObj: sessionStorage.getItem('searchObj') !== 'undefined' ? JSON.parse(sessionStorage.getItem('searchObj')) : {}
}
const mutations = {
  // changeShowtab1(state, data) {
  //   state.showtab1 = data;
  //   sessionStorage.setItem("showtab1", data);
  // },
  changeAttrList(state, data) {
    state.attrList = data
    var e = JSON.stringify(data)
    sessionStorage.setItem('attrList', e)
  },
  changeSearchObj(state, data) {
    state.searchObj = data
    var e = JSON.stringify(data)
    sessionStorage.setItem('searchObj', e)
  },
  changeListTotal(state, data) {
    state.listTotal = Number(data)
    sessionStorage.setItem('listTotal', Number(data))
  },
  changeQuery(state, data) {
    state.queryParams = data
    var e = JSON.stringify(data)
    sessionStorage.setItem('queryParams', e)
  },
  CHANGE_SHOWBACK: (state, data) => {
    state.isShowBack = data
    sessionStorage.setItem('isShowBack', data)
  },
  changeHistory(state, data) {
    state.historyArr.push(data)
    if (state.historyArr.length > 10) {
      state.historyArr.shift()
    }
    sessionStorage.setItem('historyArr', JSON.stringify(state.historyArr))
  },
  clearHistory(state, value) {
    state.historyArr = []
    sessionStorage.setItem('historyArr', [])
  },
  changeAssetsObj(state, data) {
    state.assetsObj = data
    var e = JSON.stringify(data)
    sessionStorage.setItem('assetsObj', e)
  }
}
export default {
  namespaced: true,
  state,
  mutations
}
